<?php
session_start();
ob_start();
if (isset($_SESSION["id"]))
    header("Location: http://localhost:92/nqt-web2/public/index.php?uid=" . $users[$index]['id']);
?>

<html>
    
      
        
      
      
 <body id="khung">
<?php require_once '../model/users.php'; ?>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <link rel="stylesheet" type="text/css" href='../public/css/style.css'>
        <title>Nguyen Quoc Thong</title>
<form method="POST"> 
    <table>
        <tr>
            <td>Username: </td>
            <td><input type="text" name="username" id="name"></td>
        </tr>
        <tr>
            <td>Password: </td>
            <td><input type="password" name="password" id="password">
        </tr>
    </table>
    <input type="submit" name="submit" value="Enter"></p>
</form>

<?php if (isset($_POST['submit'])): ?>
                            <?php
                            $username = $_POST['username'];
                            $password = $_POST['password'];
                            $isOk = FALSE;
                            $index = -1;
                            for ($i = 0; $i < count($users); $i++) {
                                if ((strcmp($users[$i]['username'], $username) == 0) &&
                                        (strcmp($users[$i]['password'], $password) == 0)) {
                                    $isOk = TRUE;
                                    $index = $i;
                                }
                            }
                            if ($isOk) {
                                $_SESSION["id"] = $users[$index]["id"];
                                header("Location: http://localhost:92/nqt-web2/public/index.php ");
                            } else {
                                echo 'lỗi';
                            }
                            ?>
                        <?php endif; ?>

<?php ob_end_flush(); ?>